package cn.lf.android.lawfirm.outgoingregistration.controller;


import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.outgoingregistration.modle.OutGoing;
import cn.lf.android.lawfirm.outgoingregistration.modle.OutGoingInfo;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFeeInfo;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.JsonBeans;
import cn.lf.android.lawfirm.utils.SPUtil;

/**
 * 列表
 */
public class OutGoingInfoConroller extends BaseController {
    OutGoingInfoCallback mOutGoingInfoCallback;
    private Context context;

    public OutGoingInfoConroller(OutGoingInfoCallback callback, Context context) {
        this.mOutGoingInfoCallback = callback;
        this.context = context;
    }


    /**
     * @param Id
     */
    public void onOutGoingInfo(String Id) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("Id", Id);
        DebugLog.e("Id==" + Id);
        new MyOkHttpClient().doGet(AppConfig.LSCaseApproveRecordList_Detail, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("外出信息==" + response);
                        JSONObject myJsonObject;
                        JSONObject responsObject;
                        Boolean isSuc;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                responsObject = myJsonObject.getJSONObject("responsObject");
                                OutGoingInfo bean = JSON.parseObject(responsObject.toString(), OutGoingInfo.class);
                                mOutGoingInfoCallback.onOutGoingInfouccessed(bean);
                            } else {
                                mOutGoingInfoCallback
                                        .onOutGoingInfoFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        mOutGoingInfoCallback.onOutGoingInfoFailed();
                        dismissProgressDia();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }


    public interface OutGoingInfoCallback {
        public void onOutGoingInfouccessed(OutGoingInfo beans);

        public void onOutGoingInfoFailed();

    }

}
